Attribute VB_Name = "module"
Global gsMsg As String
Global gsNetworkPath As String
Global gsSQLConn As String
Global gsExtesionDatabase As String
Global gsAccessConn As String
Global gsExtesion As String
Global gsAccess As String
Global giFont1 As String
Global giFont2 As String
Global giFont3 As String
Global gsNFormat As String
Global gsCrrMonth As String
Global gsCurrency As String
Global giTo As String
Global gsExpiry As String
Global gsUsername As String
Global gsDatabase As String
Global gsPassword As String
Global gsIP As String
Global gsPort As String

Sub Main()
    gsMsg = " Accounting Systems"
    Flash.Show
    Flash.lbTitle.Caption = Msg
    Flash.lbDesigned.Caption = "Designed by Saigon Infotech, Inc."
    Flash.Refresh
    Call getDBInfo
    gsNetworkPath = App.Path() & "\"
    gsAccessConn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & gsNetworkPath & gsAccess
    gsNFormat = "#,##0"
    giFont1 = 9: giFont2 = 8: giFont3 = 10
    gsFont1 = "VN-NTime"
    gsFont2 = "Tahoma": gsFont3 = "VNI-Times"
    gsExpiry = "30/06/2003"
    gsCurrency = "VND"
    giFrom = 1999
    gsCrrMonth = "09/2001"
    giTo = Val(Right(gsExpiry, 4))
    Unload Flash
    frmLogin.Show 1
End Sub
Sub getDBInfo()
    On Error GoTo err
    Dim f As Integer
    Dim strName As String, strWord As String
    Dim strFile As String
    f = FreeFile
    strFile = App.Path & "\config.ini"
    Open strFile For Input As f
    Do While Not EOF(f)
        Line Input #f, strWord
        If LCase(Left(strWord, InStr(1, strWord, "=") - 1)) = "database" Then
            gsDatabase = Mid(strWord, InStr(1, strWord, "=") + 1)
        End If
        If LCase(Left(strWord, InStr(1, strWord, "=") - 1)) = "ip" Then
            gsIP = Mid(strWord, InStr(1, strWord, "=") + 1)
        End If
        If LCase(Left(strWord, InStr(1, strWord, "=") - 1)) = "port" Then
            gsPort = Mid(strWord, InStr(1, strWord, "=") + 1)
        End If
        If LCase(Left(strWord, InStr(1, strWord, "=") - 1)) = "access" Then
            gsAccess = Mid(strWord, InStr(1, strWord, "=") + 1)
        End If
        If LCase(Left(strWord, InStr(1, strWord, "=") - 1)) = "extensiondatabase" Then
            gsExtesion = Mid(strWord, InStr(1, strWord, "=") + 1)
        End If
    Loop
    Close f
    
    Exit Sub
err:
    Beep
    gsUsername = "sa"
    gsDatabase = "Northwind"
    gsIP = "."
    gsPort = "1433"
    gsAccess = "Northwind.mdb"
    gsExtesion = "InterShop"
End Sub

Function Authentication(ByVal U As String, P As String) As Boolean
On Error GoTo err
    gsSQLConn = "Provider=SQLOLEDB.1;Persist Security Info=False;UID=" & U & ";PWD=" & P & ";Initial Catalog=" & gsDatabase & ";Server=" & gsIP & ";Port=" & gsPort
    gsExtesionDatabase = "Provider=SQLOLEDB.1;Persist Security Info=False;UID=" & U & ";PWD=" & P & ";Initial Catalog=" & gsExtesion & ";Server=" & gsIP & ";Port=" & gsPort
    Dim Conn
    Set Conn = CreateObject("ADODB.Connection")
    Conn.Open gsSQLConn
    Set Conn = Nothing
    Authentication = True
    Exit Function
err:
    MsgBox "Error occur " & err.Description, vbCritical, gsMsg
    Authentication = False
End Function

Function doSQL(ByVal strSQL As String) As Integer
    On Error GoTo err
    Dim i As Integer
    Dim lcConn
    Set lcConn = CreateObject("ADODB.Connection")
    lcConn.Open gsSQLConn
    lcConn.Execute strSQL, i
    Set lcConn = Nothing
    doSQL = i
    Exit Function
err:
    doSQL = -1
End Function
Function ExecuteSQL(ByVal strSQL As String) As Integer
    On Error GoTo err
    Dim i As Integer
    Dim lcConn
    Set lcConn = CreateObject("ADODB.Connection")
    lcConn.Open gsExtesionDatabase
    lcConn.Execute strSQL, i
    Set lcConn = Nothing
    ExecuteSQL = i
    Exit Function
err:
    ExecuteSQL = -1
End Function



